package Udp;

import java.net.DatagramPacket;
import java.net.DatagramSocket;

public class UdpServer {
    public static void main(String[] args) throws Exception{
        /**
         * 开放端口
         * 接受包
         * 关闭连接
         */
        DatagramSocket socket = new DatagramSocket(999);//开放端口

        byte[] buffer = new byte[1024];
        DatagramPacket packet = new DatagramPacket(buffer,0,buffer.length);//要接受的包
        socket.receive(packet);//接收包

        System.out.println(new String(packet.getData(),0, packet.getLength()));

        socket.close();//关闭连接
    }
}
